package com.lh0811.forge.dependency.basic_code.encrypt;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.mindrot.jbcrypt.BCrypt;

import java.io.Serializable;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;

public class PwdUtil {
    private static final String UPPER_CASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    private static final String LOWER_CASE = UPPER_CASE.toLowerCase();
    private static final String DIGITS = "0123456789";
    private static final String SPECIAL_CHARS = "!@#$%^&*()_+";
    private static final int PASSWORD_LENGTH = 10;

    public static String generateRandomPassword() {
        return generateRandomPassword(PASSWORD_LENGTH);
    }

    public static String generateRandomPassword(int length) {
        List<String> chars = new ArrayList<>();
        chars.add(UPPER_CASE);
        chars.add(LOWER_CASE);
        chars.add(DIGITS);
        chars.add(SPECIAL_CHARS);

        StringBuilder password = new StringBuilder();
        SecureRandom random = new SecureRandom();

        for (int i = 0; i < length; i++) {
            int randomIndex = random.nextInt(chars.size());
            password.append(chars.get(randomIndex).charAt(random.nextInt(chars.get(randomIndex).length())));
        }

        return password.toString();
    }

    public static String gensalt() {
        return BCrypt.gensalt();
    }

    public static String hashPassword(String plainTextPassword, String salt) {
        return BCrypt.hashpw(plainTextPassword, salt);
    }

    public static void main(String[] args) {

    }

    @Getter
    @Setter
    @AllArgsConstructor
    @NoArgsConstructor
    public static class ApplyApproveResultNoticeMqMsg implements Serializable {

        private String reqSn;
        private String applicationNo;
        private String approvalStatus;
        private String approvalSuggestion;
        private String approveNo;
        private String flowId;
        private String taskId;
        private String approveUserNo;
        private String approveUserName;
        private String aproveTime;

    }

}